import UIKit

class LoginViewController: BaseViewController {
    private let loginButton: UIButton = {
        let button = UIButton(type: .system)
        button.setTitle("登录", for: .normal)
        button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 18)
        button.backgroundColor = UIColor.systemBlue
        button.setTitleColor(.white, for: .normal)
        button.layer.cornerRadius = 8
        return button
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        title = "登录"
        view.backgroundColor = .white
        setupUI()
    }

    private func setupUI() {
        view.addSubview(loginButton)
        loginButton.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            loginButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            loginButton.centerYAnchor.constraint(equalTo: view.centerYAnchor),
            loginButton.widthAnchor.constraint(equalToConstant: 120),
            loginButton.heightAnchor.constraint(equalToConstant: 44)
        ])
        loginButton.addTarget(self, action: #selector(loginAction), for: .touchUpInside)
    }

    @objc private func loginAction() {
        // 登录成功，切换到主TabBar界面
        let tabBar = BaseTabBar()
        let module1VC = Module1ViewController()
        module1VC.tabBarItem = UITabBarItem(title: "模块1", image: nil, tag: 0)
        let module2VC = Module2ViewController()
        module2VC.tabBarItem = UITabBarItem(title: "模块2", image: nil, tag: 1)
        let settingsVC = SettingsViewController()
        settingsVC.tabBarItem = UITabBarItem(title: "设置", image: nil, tag: 2)
        tabBar.viewControllers = [module1VC, module2VC, settingsVC].map { UINavigationController(rootViewController: $0) }
        if let window = UIApplication.shared.windows.first {
            window.rootViewController = tabBar
            window.makeKeyAndVisible()
        }
    }
} 